package com.itheima.controller;

import com.aliyun.oss.AliOSSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
public class UploadController {

    @Autowired
    private AliOSSUtil aliOSSUtil;
    @PostMapping("/upload")
    public String upload(MultipartFile image) throws Exception {
        //检查文件是否为空
        if (image == null || image.isEmpty()) {
            return "上传文件不能为空";
        }
        //上传文件到阿里云 OSS
        return aliOSSUtil.getUrl(image);
    }

}